import { FeeRules } from './feeRule';
let _FeeRules = FeeRules;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import FeeRuleMock from './mk/mng/staff/feeRuleMock';
 * FeeRuleMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mk/mng/staff/feeRule/listKey').reply(config => {
      let params = config.params;
      let mockFeeRules = _FeeRules.filter(feeRule => {
      	if(params.mkStaff||params.mkStaff==''){ if( feeRule.mkStaff.indexOf(params.mkStaff)>=0) return true;}
      	if(params.mkDeptid||params.mkDeptid==''){ if( feeRule.mkDeptid.indexOf(params.mkDeptid)>=0) return true;}
      	if(params.id||params.id==''){ if( feeRule.id.indexOf(params.id)>=0) return true;}
      	if(params.pct||params.pct==''){ if( feeRule.pct.indexOf(params.pct)>=0) return true;}
      	if(params.feeRuleDesc||params.feeRuleDesc==''){ if( feeRule.feeRuleDesc.indexOf(params.feeRuleDesc)>=0) return true;}
      	if(params.pctType||params.pctType==''){ if( feeRule.pctType.indexOf(params.pctType)>=0) return true;}
      	if(params.isAcctGoods||params.isAcctGoods==''){ if( feeRule.isAcctGoods.indexOf(params.isAcctGoods)>=0) return true;}
      	if(params.isAcctShop||params.isAcctShop==''){ if( feeRule.isAcctShop.indexOf(params.isAcctShop)>=0) return true;}
      	if(params.isAcctCard||params.isAcctCard==''){ if( feeRule.isAcctCard.indexOf(params.isAcctCard)>=0) return true;}
      	if(params.isAcctArea||params.isAcctArea==''){ if( feeRule.isAcctArea.indexOf(params.isAcctArea)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockFeeRules
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mk/mng/staff/feeRule/list').reply(config => {
      let params = config.params;
      let mockFeeRules = _FeeRules.filter(feeRule => {
      	var isTrue=false;
      	if(params.mkStaff||params.mkStaff==''){if(feeRule.mkStaff.indexOf(params.mkStaff)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.mkDeptid||params.mkDeptid==''){if(feeRule.mkDeptid.indexOf(params.mkDeptid)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.id||params.id==''){if(feeRule.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.pct||params.pct==''){if(feeRule.pct.indexOf(params.pct)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.feeRuleDesc||params.feeRuleDesc==''){if(feeRule.feeRuleDesc.indexOf(params.feeRuleDesc)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.pctType||params.pctType==''){if(feeRule.pctType.indexOf(params.pctType)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isAcctGoods||params.isAcctGoods==''){if(feeRule.isAcctGoods.indexOf(params.isAcctGoods)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isAcctShop||params.isAcctShop==''){if(feeRule.isAcctShop.indexOf(params.isAcctShop)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isAcctCard||params.isAcctCard==''){if(feeRule.isAcctCard.indexOf(params.isAcctCard)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isAcctArea||params.isAcctArea==''){if(feeRule.isAcctArea.indexOf(params.isAcctArea)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockFeeRules
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockFeeRules.length;
      mockFeeRules = mockFeeRules.filter((feeRule, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockFeeRules,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mk/mng/staff/feeRule/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _FeeRules = _FeeRules.filter(feeRule => feeRule.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mk/mng/staff/feeRule/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _FeeRules = _FeeRules.filter(feeRule => !params.includes(feeRule.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mk/mng/staff/feeRule/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { mkStaff,mkDeptid,id,pct,feeRuleDesc,pctType,isAcctGoods,isAcctShop,isAcctCard,isAcctArea } = params;
      _FeeRules.some(feeRule => {
        if (feeRule.id === id) {
			feeRule.mkStaff = mkStaff;
			feeRule.mkDeptid = mkDeptid;
			feeRule.id = id;
			feeRule.pct = pct;
			feeRule.feeRuleDesc = feeRuleDesc;
			feeRule.pctType = pctType;
			feeRule.isAcctGoods = isAcctGoods;
			feeRule.isAcctShop = isAcctShop;
			feeRule.isAcctCard = isAcctCard;
			feeRule.isAcctArea = isAcctArea
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mk/mng/staff/feeRule/add').reply(config => {
      var params = JSON.parse( config.data );
      let { mkStaff,mkDeptid,id,pct,feeRuleDesc,pctType,isAcctGoods,isAcctShop,isAcctCard,isAcctArea } = params;
      _FeeRules.push({
		mkStaff:mkStaff,
		mkDeptid:mkDeptid,
		id:id,
		pct:pct,
		feeRuleDesc:feeRuleDesc,
		pctType:pctType,
		isAcctGoods:isAcctGoods,
		isAcctShop:isAcctShop,
		isAcctCard:isAcctCard,
		isAcctArea:isAcctArea
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};